<?php

namespace App\Jobs;

use App\Models\ChartLog;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class DelChartLogJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    private $message_id;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($message_id)
    {
        $this->message_id=$message_id;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $list=ChartLog::where("is_delete",1)->get();
        DB::beginTransaction();
        try {
            foreach ($list as $key=>$value){
                ChartLog::find($value["id"])->delete();
            }
            DB::commit();
        }catch (\Exception $exception){
            DB::rollBack();
        }
    }
}
